package m202405.d13;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/13 16:26
 */
public class Q437 {

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(1);
        root.left.right = new TreeNode(1);
        Q437 q437 = new Q437();
        q437.pathSum(root, 3);
    }

    public int pathSum(TreeNode root, int targetSum) {
        if (root == null) {
            return counter;
        }
        find(root, 0, targetSum);
        pathSum(root.left, targetSum);
        pathSum(root.right, targetSum);
        return counter;
    }

    int counter = 0;

    public void find(TreeNode root, long sum, int targetSum) {
        if (root == null) {
            return;
        }
        long temp = sum + root.val;
        if (temp == targetSum) {
            counter++;
        }
        find(root.left, temp, targetSum);
        find(root.right, temp, targetSum);
    }
}
